package insat.challenge;

import insat.challenge.metier.PlaceCategory;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.SubMenu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class EstablishmentActivity extends DashboardActivity implements OnItemClickListener {

	private ListView listView;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.placecategory);

		listView = (ListView) findViewById(R.id.listView_placecategory);

		setBaseAdapter();

	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		PlaceCategory placeCategory= (PlaceCategory) arg0.getItemAtPosition(arg2);
		String name = placeCategory.getName();
		String id = placeCategory.getId();
		Object item = arg0.getItemAtPosition(arg2);
		
		Intent intent = new Intent(this, CategoryInfoActivity.class);
		Bundle bundle = new Bundle();
		bundle.putString("name", name);
		bundle.putString("id", id);
		
		intent.putExtra("android.intent.extra.INTENT", bundle);
		startActivity(intent);
		//startActivityForResult(intent, 0);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub

		SubMenu m = menu.addSubMenu(0, 0, 0, "");
		m.add("essai");
		return super.onCreateOptionsMenu(menu);
	}

	private void setBaseAdapter() {
		PlaceCategory placeCategory =new PlaceCategory();
		
		ArrayAdapter<PlaceCategory> adapter = new ArrayAdapter<PlaceCategory>(this,
				android.R.layout.simple_list_item_1, placeCategory.getCategories());
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(this);

	}

}
